<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery-3.4.1.js"></script>
</head>
<body>
    账号：<input type="text" name="username" id="uname"><br>
    密码：<input type="text" name="password" id="pwd"><br>
    <button type="button" onclick="post1()">post请求不带参数</button><br>
    <button type="button" onclick="post2()">post请求带参数</button><br>
    <button type="button" onclick="post3()">post请求带参数[json]</button><br>
</body>
<script>
    function post1(){
        $.ajax({
            type: 'POST',
            url: 'http://localhost:3000/post1',
            success: function(res){
                console.log(res);
            },
            error: function (xhr, errortype){
                console.log(xhr.status);
            }
        })
    }
    function post2(){
        var uname = document.getElementById("uname").value
        var pwd = document.getElementById("pwd").value
        $.ajax({
            type: 'POST',
            url: 'http://localhost:3000/post2',
            data: {username: uname, password: pwd},
            dataType: 'json',
            success: function(res){
                console.log(res);
            },
            error: function (xhr, errortype){
                console.log(xhr.status);
            }
        })
    }
    function post3(){
        $.ajax({
            type: 'POST',
            url: 'http://localhost:3000/post3',
            data: {username: 'Jack', password: 322383},
            dataType: 'json',
            success: function(res){
                console.log(res);
            },
            error: function (xhr, errortype){
                console.log(xhr.status);
            }
        })
    }
</script>
</html>